package controller;

import javax.swing.JComboBox;

import model.IEBenchmarkProcess;
import model.IManufacturingMethod;
import view.ChooseMethods;
import view.EBenchmarkPanel;
import controller.auxillary.MMComboBoxListener;

/**
 * The {@code CtrChooseMethods} controls the behavior of the
 * {@code ChooseMethods} panel.
 * @author Oliver Eckstein
 *
 */
public class CtrChooseMethods implements IControllable {
    
	/**
	 * The controller's view.
	 */
	private ChooseMethods panel;
    
	/**
	 * The referenced calculation model.
	 */
	private IEBenchmarkProcess eBenchmark;
	
	/**
	 * The controller of the information panel.
	 */
    private CtrInformationPanel infoPanelController;
    
    /**
     * To create a new instance of a {@code CtrChooseMethods} and connect it
     * to the model and the controller of the information panel.
     * @param eBenchmark the application's model.
     * @param infoPanelController the controller of the information panel.
     */
    public CtrChooseMethods(IEBenchmarkProcess eBenchmark,
            CtrInformationPanel infoPanelController) {
        this.eBenchmark = eBenchmark;
        this.infoPanelController = infoPanelController;
        createPanel();        
    }
    
    /**
     * To create the controller's panel as follows:
     * First, get all implemented manufacturing types of this EBenchmark.
     * Then translate them into German and create the panel.
     */
    private void createPanel() {
        int i = 0;
        // Create an array of the size with as much as existing manufacturing
        // method types.
        String[] manuMethods =
                new String[IManufacturingMethod.SubType.values()
                           .length];
        // Fill the array.
        for(IManufacturingMethod.SubType manuMethod : 
                IManufacturingMethod.SubType.values()) {
            manuMethods[i++] = eBenchmark.typeToString(manuMethod);
            // Create the panel.
            panel = new ChooseMethods(manuMethods, infoPanelController);
        }        
        
        // Add a manufacturing method combobox listener to every created
        // combobox.
        for(JComboBox<Integer> cb : panel.getComboBoxes()) {
            cb.addActionListener(new MMComboBoxListener(
                    eBenchmark,
                    cb,
                    infoPanelController));
        }
    }
    
    @Override
    public EBenchmarkPanel getView() {
        return panel;
    }
    
    @Override
    public void createView(String logoPath) {
    	// Nothing to do here.
    }
}
